home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_assigns.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  10.6 KB  |  328 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. int  asscnt;
  33.  
  34. static APTR AssPool = NULL;
  35.  
  36. __asm __saveds LONG asslist_dspfunc(register __a2 char **array, register __a1 struct AssEntry *assentry, register __a0 struct Hook *hook)
  37. {
  38.    if (assentry) {
  39.       *array++ = assentry->ass_address;
  40.       *array++ = assentry->ass_name;
  41.       *array++ = assentry->ass_path;
  42.       *array   = NULL;
  43.    } else {
  44.       *array++ = ESC "bAddress";
  45.       *array++ = ESC "bName";
  46.       *array++ = ESC "bPath";
  47.       *array   = NULL;
  48.    }
  49.    return(0);
  50. }
  51.  
  52. struct Hook asslist_dsphook = {
  53.  {NULL, NULL},
  54.  (ULONG (* )())asslist_dspfunc,
  55.  NULL, NULL
  56. };
  57.  
  58. __asm __saveds LONG asslist_cmpnamefunc (register __a1 struct AssEntry *ae1, register __a2 struct AssEntry *ae2)
  59. {
  60.     LONG result;
  61.  
  62.     result = strcmpi(ae1->ass_name, ae2->ass_name);
  63.     if (result == 0) result = ae2->ass_type - ae1->ass_type;
  64.     if (result == 0) result = strcmpi(ae1->ass_realpath, ae2->ass_realpath);
  65.  
  66.     return result;
  67. }
  68.  
  69. struct Hook asslist_cmpnamehook = {
  70.  {NULL, NULL},
  71.  (ULONG (* )())asslist_cmpnamefunc,
  72.  NULL, NULL
  73. };
  74.  
  75. __asm __saveds LONG asslist_cmppathfunc (register __a1 struct AssEntry *ae1, register __a2 struct AssEntry *ae2)
  76. {
  77.     LONG result;
  78.  
  79.     result = strcmpi(ae1->ass_realpath, ae2->ass_realpath);
  80.     if (result == 0) result = strcmpi(ae1->ass_name, ae2->ass_name);
  81.  
  82.     return result;
  83. }
  84.  
  85. struct Hook asslist_cmppathhook = {
  86.  {NULL, NULL},
  87.  (ULONG (* )())asslist_cmppathfunc,
  88.  NULL, NULL
  89. };
  90.  
  91. void FreeAssigns (void)
  92. {
  93.     MyFreePoolStructs(&AssPool, asstext, NULL, asslist);
  94. }
  95.  
  96. int GetAssigns (struct AssEntry **first) {
  97.    struct   AssEntry       *assentry,*previous = NULL;
  98.    struct   DosList        *dev;
  99.    struct   AssignList     *list;
  100.    struct   FileInfoBlock  *infoBlock;
  101.  
  102.    int asscnt = 0;
  103.    *first = 0;
  104.  
  105.    if (!AssPool) AssPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  106.  
  107.    dev = DOSLIST;
  108.  
  109.    if (clientstate) {
  110.       char  tmpbuffer[256];
  111.  
  112.       if (SendDaemon ("GetAssList")) {
  113.          while ((assentry = tbAllocPooled(AssPool, sizeof(struct AssEntry))) \
  114.            && (ReceiveDecodedEntry ((UBYTE *) assentry, sizeof (struct AssEntry) - 4)) \
  115.            && (sgets (client_socket, tmpbuffer, 256))) {
  116.  
  117.             if (assentry->ass_path = tbAllocPooled(AssPool, strlen (tmpbuffer) + 1)) {
  118.                strncpy (assentry->ass_path, tmpbuffer, strlen (tmpbuffer) + 1);
  119.             }
  120.  
  121.             IsHex (assentry->ass_address, (long *) &assentry->ass_adr);
  122.  
  123.             if (! *first)
  124.                *first = assentry;
  125.             if (previous)
  126.                previous->ass_next = assentry;
  127.  
  128.             asscnt++;
  129.             previous = assentry;
  130.          }
  131.       }
  132.    } else {
  133.       if (infoBlock = AllocDosObject(DOS_FIB, TAG_DONE)) {
  134.          while ((dev != 0) && (assentry = tbAllocPooled(AssPool, sizeof (struct AssEntry)))) {
  135.             if ((dev->dol_Type == DLT_DIRECTORY) || (dev->dol_Type == DLT_LATE) || (dev->dol_Type == DLT_NONBINDING)) {
  136.                if (! *first)
  137.                   *first = assentry;
  138.                if (previous)
  139.                   previous->ass_next = assentry;
  140.    
  141.                assentry->ass_adr = (char *) dev;
  142.                _sprintf (assentry->ass_address, "$%08lx", dev);
  143.                b2cstrn(dev->dol_Name, assentry->ass_name, 20);
  144.    
  145.                if (Examine (dev->dol_Lock, infoBlock)) {
  146.                   tmpstr[0] = '\0';
  147.                   NameFromLock (dev->dol_Lock, tmpstr, PATHLENGTH);
  148.    
  149.                   if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = tbAllocPooled(AssPool, strlen (tmpstr) + 1)) && (assentry->ass_realpath = tbAllocPooled (AssPool, strlen (tmpstr) + 1))) {
  150.                      strcpy (assentry->ass_path, tmpstr);
  151.                      strcpy (assentry->ass_realpath, tmpstr);
  152.                   } else if ((dev->dol_Type == DLT_LATE) && (assentry->ass_path = tbAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3)) && (assentry->ass_realpath = tbAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3))) {
  153.                      _sprintf (assentry->ass_path, "<%s>", dev->dol_misc.dol_assign.dol_AssignName);
  154.                      strcpy(assentry->ass_realpath, dev->dol_misc.dol_assign.dol_AssignName);
  155.                   } else if ((dev->dol_Type == DLT_NONBINDING) && (assentry->ass_path = tbAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3)) && (assentry->ass_realpath = tbAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3))) {
  156.                      _sprintf (assentry->ass_path, "[%s]", dev->dol_misc.dol_assign.dol_AssignName);
  157.                      strcpy(assentry->ass_realpath, dev->dol_misc.dol_assign.dol_AssignName);
  158.                   }
  159.                   assentry->ass_type = dev->dol_Type;
  160.                }
  161.                asscnt++;
  162.    
  163.                previous = assentry;
  164.                list = dev->dol_misc.dol_assign.dol_List;
  165.    
  166.                while ((list) && (assentry = tbAllocPooled (AssPool, sizeof(struct AssEntry)))) {
  167.                   if (previous)
  168.                      previous->ass_next = assentry;
  169.    
  170.                   assentry->ass_adr = (char *) (list->al_Lock);
  171.                   _sprintf (assentry->ass_address, "$%08lx", BADDR(list->al_Lock));
  172.                   b2cstr(dev->dol_Name, assentry->ass_name);
  173.    
  174.                   if (Examine (list->al_Lock, infoBlock)) {
  175.                      tmpstr[0] = '\0';
  176.                      NameFromLock (list->al_Lock, tmpstr, PATHLENGTH);
  177.    
  178.                      if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = tbAllocPooled(AssPool, strlen (tmpstr) + 7)) && (assentry->ass_realpath = tbAllocPooled (AssPool, strlen (tmpstr) + 7))) {
  179.                         _sprintf (assentry->ass_path, " +  %s", tmpstr);
  180.                         strcpy(assentry->ass_realpath, tmpstr);
  181.                      }
  182.                   }
  183.                   asscnt++;
  184.    
  185.                   previous = assentry;
  186.                   list = (struct AssignList *) (list->al_Next);
  187.                }
  188.             }
  189.             dev = (struct DosList *)BADDR(dev->dol_Next);
  190.          }
  191.          FreeDosObject(DOS_FIB, infoBlock);
  192. //    infoBlock = NULL;
  193.       }
  194.    }
  195.    return (asscnt);
  196. }
  197.  
  198. void PrintAssigns (char *filename) {
  199.    int   i=1;
  200.    BPTR  handle;
  201.    struct AssEntry *entryp = NULL;
  202.  
  203.    handle = HandlePrintStart (filename);
  204.    if ((handle) && (PrintOneLine (handle, "\n  Address  Name       Path\n\n"))) {
  205.       if (! WI_Assigns) {
  206.          i = GetAssigns (&entryp);
  207.       }
  208.       if (i) {
  209.          for (i=0;;i++) {
  210.             if (WI_Assigns)
  211.                DoMethod (asslist,MUIM_List_GetEntry,i,&entryp);
  212.             if (!entryp) break;
  213.  
  214.             _sprintf (tmpstr2, " %9s %-10s %s\n", entryp->ass_address, entryp->ass_name, entryp->ass_path);
  215.             if (! (PrintOneLine (handle, tmpstr2)))
  216.                break;
  217.  
  218.             if (! WI_Assigns)
  219.                entryp = entryp->ass_next;
  220.          }
  221.       }
  222.    }
  223.    HandlePrintStop();
  224. }
  225.  
  226. void ShowAssigns (void) {
  227.    struct AssEntry *ass;
  228.  
  229.    ApplicationSleep();
  230.    set (asslist,MUIA_List_Quiet,TRUE);
  231.    set (asslist,MUIA_List_CompareHook,asslist_cmphook_ptr);
  232.    set (BT_AssRemove, MUIA_Disabled, TRUE);
  233.  
  234.    FreeAssigns();
  235.    asscnt = GetAssigns (&ass);
  236.  
  237.    while (ass) {
  238.       InsertSortedEntry (asslist, (APTR *) &ass);
  239.       ass = ass->ass_next;
  240.    }
  241.  
  242.    SetCountText (asscount, asscnt);
  243.    AwakeApplication();
  244.    set (asslist,MUIA_List_Quiet,FALSE);
  245. }
  246.  
  247. void SendAssList (void) {
  248.    struct AssEntry *ass;
  249.  
  250.    FreeAssigns();
  251.    asscnt = GetAssigns (&ass);
  252.  
  253.    while (ass) {
  254.       SendEncodedEntry ((UBYTE *) ass, sizeof (struct AssEntry) - 4);
  255.       SendClient ((UBYTE *) ass->ass_path);
  256.       ass = ass->ass_next;
  257.    }
  258.    FreeAssigns();
  259. }
  260.  
  261.  
  262. APTR WI_Assigns, asslist, asstext, asscount, CY_AssSort;
  263. int  asssortstate = 0;
  264. APTR BT_AssUpdate, BT_AssPrint, BT_AssRemove, BT_AssExit;
  265.  
  266. APTR AssSortList[] = {
  267.    &list_cmpnormalhook,
  268.    &asslist_cmpnamehook,
  269.    &list_cmpaddresshook,
  270.    &asslist_cmppathhook,
  271.    NULL
  272. };
  273.  
  274. static const char *CYA_AssSortText[] = {
  275.    "normal",
  276.    "name",
  277.    "address",
  278.    "path",
  279.    NULL
  280. };
  281.  
  282. char assigns_title[WINDOWTITLELEN];
  283.  
  284. void AssignsWindow (BOOL state) {
  285.    if (state) {
  286.       if (WI_Assigns) {
  287.          ShowAssigns();
  288.       } else {
  289.          WI_Assigns = WindowObject,
  290.          MUIA_Window_Title, MyGetWindowTitle (assigns_title, "ASSIGNS"),
  291.          MUIA_HelpNode, AssignsText,
  292.          MUIA_Window_ID, MakeListID('A','S','S','I'),
  293.          WindowContents, VGroup,
  294.             Child, asslist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2",&asslist_dsphook),
  295.             Child, MyBelowSortedListview (&asstext, &asscount, &CY_AssSort, CYA_AssSortText, asssortstate),
  296.             Child, MyVSpace(2),
  297.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  298.                Child, BT_AssUpdate  = KeyButtonA (UpdateText,ID_ASSUPDATE),
  299.                Child, BT_AssPrint   = KeyButtonA (PrintText ,ID_ASSPRINT),
  300.                Child, BT_AssRemove  = KeyButtonA (RemoveText,ID_ASSREMOVE),
  301.                Child, BT_AssExit    = KeyButtonA (ExitText  ,ID_ASSEXIT),
  302.             End,
  303.          End, End;
  304.  
  305.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Assigns);
  306.          DoMethod (WI_Assigns,MUIM_Window_SetCycleChain,asslist,CY_AssSort,BT_AssUpdate,BT_AssPrint,BT_AssRemove,BT_AssExit,NULL);
  307.          DoMethod (CY_AssSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_ASSSORT);
  308.  
  309.          SetCloseRequest (WI_Assigns,ID_ASSEXIT);
  310.          SetListActive (asslist,ID_ASSLV_ACTIVE);
  311.  
  312.          ShowAssigns();
  313.  
  314.          SetWindowOpen (WI_Assigns,asslist,ID_ASSEXIT);
  315.       }
  316.    } else if ((! state) && (WI_Assigns)) {
  317.       SetWindowClose (WI_Assigns,TRUE);
  318.  
  319.       FreeAssigns();
  320.  
  321.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Assigns);
  322.       MUI_DisposeObject (WI_Assigns);
  323.       WI_Assigns = NULL;
  324.       asslist = NULL;
  325.    }
  326. }
  327.  
  328.